package com.controladores.controlvehicular;



import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;



public class Sql {
	public static final String ID_FILA="_id";
	public static final String ID_USUARIO="NombreUsuario_controlador";
	public static final String ID_CONTRASENA="contrasena_controlador";
	public static final String ID_NOMBRE="Nombre_controlador";
	public static final String ID_APELLIDO="Apellido_controlador";
	public static final String ID_TELEFONO="Telefono_persona";
	public static final String ID_DIRECCION="Direccion_controlador";
	public static final String ID_CODIGO="Codigo_controlador";

	private static final String N_DB = "SIMERT";
	private static final String N_TABLA = "Controlador";
	private static final int VERSION_DB  = 1;
	
	private BDHelper nHelper;
	private final Context nContexto;
	private SQLiteDatabase  nDB;
	
	private static class BDHelper extends SQLiteOpenHelper{
		
		public BDHelper(Context context) {
			super(context, N_DB, null, VERSION_DB);
			// TODO Auto-generated constructor stub
			
			
		}

		@Override
		public void onCreate(SQLiteDatabase db) {
			// TODO Auto-generated method stub
			db.execSQL("CREATE TABLE " + N_TABLA + "(" +
					
					ID_FILA + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
					ID_USUARIO + " TEXT NOT NULL, " +
					ID_CONTRASENA + " TEXT NOT NULL, " +
					ID_NOMBRE + " TEXT NOT NULL, " + 
					ID_APELLIDO + " TEXT NOT NULL, " +
					ID_TELEFONO + " TEXT NOT NULL, " +
					ID_DIRECCION + " TEXT NOT NULL, " +
					ID_CODIGO + " TEXT NOT NULL);" 

							
					);
		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			// TODO Auto-generated method stub
			db.execSQL("DROP TABLE IT EXISTS " + N_TABLA);
			onCreate(db);
		}
	}
	public Sql (Context c){
		nContexto = c;
	}
	public Sql abrir() throws Exception{
		nHelper = new BDHelper(nContexto);
		nDB = nHelper.getWritableDatabase();
		return this;
	}
	public void cerrar() {
		// TODO Auto-generated method stub
		nHelper.close();
	}
	public long crearEntrada(String usua, String contra) {
		// TODO Auto-generated method stub
		ContentValues cv = new ContentValues();
		cv.put(ID_USUARIO, usua);
		cv.put(ID_CONTRASENA, contra);
		//cv.put(ID_NOMBRE, nom);
		//cv.put(ID_APELLIDO, apellido);
		//cv.put(ID_TELEFONO, telef);
		//cv.put(ID_DIRECCION, telef);
		//cv.put(ID_CODIGO, codigo);
		return nDB.insert(N_TABLA, null, cv);
		
	}
	
}
